FIX: Add destination allowlist before forwarding Bearer credential to Graph in EntraAuthMiddleware#2183
Merged
Merged
Conversation
hannahwestra25
approved these changes
Jul 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
EntraAuthMiddleware._resolve_excess_groups_asyncforwards the user's Bearer credential to a host derived from token claims (_claim_sources.src1.endpoint) and from the response body (@odata.nextLink). There was no check that these values resolve tograph.microsoft.combefore the credentialed request was made.Rather than validating the token-supplied endpoint with an allowlist, this removes it from the request entirely: the group-resolution URL is now built from a trusted, deployment-known constant (
_GRAPH_MEMBER_OBJECTS_URL), so token data cannot control the request host, path, or port. Eliminating the untrusted input is stronger than validating it; there is no longer an attacker-influenced value in the initial request to get wrong. Pagination links (@odata.nextLink) come from the Graph response body and cannot be constructed from a constant, so those retain an explicit host + scheme allowlist.This is not an exploitable bug today: the endpoint originates from a signature-validated JWT and pagination links come from a TLS-authenticated Graph response. The change makes the safety property local and robust against future changes and hardens the currently-dead path before it is re-enabled (see the existing
NOTEabout the Graph audience migration).Changes
pyrit/backend/middleware/auth.py_GRAPH_MEMBER_OBJECTS_URLconstant and build the initial group-resolution request from it, ignoring the token-supplied endpoint._claim_names["groups"]→ source key →_claim_sources(replaces the hardcodedsrc1/.endpointread)._GRAPH_HOSTS+_is_trusted_graph_url()(usingurlparse(...).hostname, sograph.microsoft.com@evil.com-style spoofs are rejected) and guard each@odata.nextLinkin the pagination loop.Tests
tests/unit/backend/test_auth_middleware.py_is_trusted_graph_url(legit Graph URLs vs.http://, wrong host, suffix-spoof, userinfo-spoof, empty).